home *** CD-ROM | disk | FTP | other *** search
/ MacHome 2001 June / MacHome Magazine Demo Disc June 2001.iso / Stuff / Software / Tools / Substitute Pro 1.8.5 / Yellow Extension Toolkit / YE main.c next >
Encoding:
C/C++ Source or Header  |  2000-02-01  |  3.5 KB  |  113 lines  |  [TEXT/CWIE]

  1. //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. //    YELLOW EXTENSION TOOLKIT
  3. //    File Name:    YE main.c
  4. //    © 1998-2000 by Rocco Moliterno-Yellowsoft. All Right Reserved
  5. //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  6.  
  7. //#include "WASTE.h" //Uncomment for using WASTE.
  8. // remember, in order to use WASTE functions, you need to add WASTE and the Libraries WASTE requires
  9.  
  10. #include "YE proto.h"
  11. #include "YE main.h"
  12.  
  13. #if GENERATING68K
  14.     #include <SetUpA4.h>
  15.     #include <A4Stuff.h>
  16. #else
  17.     ProcInfoType __procinfo = uppYellowEntryProcInfo;
  18. #endif
  19.  
  20. pascal void main(YEBlockPtr params)
  21. {
  22.     #if GENERATING68K
  23.         EnterCodeResource();
  24.     #endif
  25.  
  26. //---------------------------your code here
  27.  
  28.      GoAction(params);
  29.  
  30. //---------------------------end your code
  31.  
  32.     #if GENERATING68K
  33.         ExitCodeResource();
  34.     #endif
  35.     
  36. }
  37.  
  38. #pragma mark EXAMPLE CODE
  39.  
  40. void GoAction(YEBlockPtr params)
  41. {
  42.  
  43. // Sanity:
  44.     if(params->signature==yellowSignature){//YellowEdit requires params->signature = 'yllw'
  45.         ParamText("\pYellow Extension sanity check: good, YellowEdit calls me!" ,"\p", "\p",  "\p");
  46.         NoteAlert(128, nil);
  47.     }
  48.     else{
  49.         ParamText((params->signature==substituteSignature)?"\pYellow Extension sanity check: good, Substitute calls me!":"\pYellow Extension sanity check: unknow caller!" ,"\p", "\p",  "\p");
  50.         NoteAlert(128, nil);// The caller isn't YellowEdit, we return, unless if you're writing
  51.         return;             // the extension for another application, or else you perform a job
  52.         }                   // without considering the caller.
  53.  
  54. // Unless we modify directly input data, we can ignore, here, any inputs parameters then
  55. // make our job: display alert/dialog, play sound, get file, play game and so on. 
  56. // We MUST always check the input parameters if we want to modify directly some 
  57. // data ex:
  58. //
  59. //  if(params->sFile)
  60. //        if((iErr=ResolveAlias(nil,params->sFile, &target, &wasChanged))!=noErr)
  61. //            iErr=FSpDelete(&target);
  62. //
  63. // or else:
  64. //  if(params->sWaste)
  65. //        WEPaste(params->sWaste);
  66. // in the following example, we don't modify directly any data but we make checks for security.
  67.  
  68.     
  69. // Remember: the calling application has responsibility to dispose any valid but unused, 
  70. // handle returned by extensions.
  71. //----------------------------------------------------------------------------------
  72.     if( (!params->sWaste) && 
  73.         (!params->sText)  &&
  74.         (!params->sFile)  &&
  75.         (!params->sList)){
  76.         ParamText("\pOh no! there's no window open!! I will return some text into a new window","\p" ,"\p" ,  "\p");
  77.         NoteAlert(128, nil);
  78.         params->rNew=true; //put new TEXT into a new window.
  79.         }    
  80.  
  81.     if(params->sWaste || params->sText){
  82.         ParamText( "\pThe call contains a valid text-related request","\p" ,"\p" ,  "\p");
  83.         NoteAlert(128, nil);
  84.  
  85.         ParamText("\pI will return some text to existing window...","\p" ,"\p" ,  "\p" );
  86.         NoteAlert(128, nil);
  87.     }
  88.  
  89.     params->rText=GetResource('TEXT',128);
  90.     DetachResource(params->rText);
  91.     HLock(params->rText);
  92.     params->rStyles=GetResource('styl',128);
  93.     DetachResource(params->rStyles);
  94.     HLock(params->rStyles);
  95.     
  96.     if(params->sFile){
  97.         Boolean wasChanged;
  98.         FSSpec  target;        
  99.         if(ResolveAlias(nil,params->sFile, &target, &wasChanged)==noErr)
  100.             ParamText( "\pThe call contains an AliasHandle:",target.name , "\p" ,  "\p");
  101.         else
  102.             ParamText( "\pThe call contains an AliasHandle, but can't resolve this damned alias!","\p"  , "\p" ,  "\p");
  103.         NoteAlert(128, nil);
  104.         }
  105.  
  106.     if(params->sList){
  107.         ParamText("\pThe call contains a List Handle","\p" ,"\p" ,  "\p");
  108.         NoteAlert(128, nil);
  109.         }
  110.  
  111. }
  112.  
  113.